using System;
using System.Windows;
using System.Collections.Generic;
using System.Windows.Media;
using NobleTech.Products.CreatureKingdom.Utils;
using NobleTech.Products.CreatureKingdom;

namespace NobleTech.Products.CreatureKingdom
{
    /// <summary>
    /// Draw a T in the target Organism
    /// </summary>
    public class TargetRenderer : IRenderer
    {
        public TargetRenderer(OrganismStats stats)
        {
        }
       
        private static DrawingBrush RenderedBrush;
        
        // The rendered brush must face downward and have a Viewport of (0,0,1,1). The client will do the size scaling, rotation and translation and will change the opacity upon death.
        public Brush Render(OrganismInfo info, PointD Location, double DirectionFacing)
        {
            // At this time, the brush is independent of the arguments, so there is no need to compute it every time.
            if (RenderedBrush == null)
            {
                RenderedBrush = new DrawingBrush();
                GeometryGroup BodyGroup = new GeometryGroup();
                BodyGroup.Children.Add(new EllipseGeometry(new Point(0.5, 0.4), 0.4, 0.4));
                BodyGroup.Children.Add(new EllipseGeometry(new Point(0.5, 0.8), 0.25, 0.25));
                BodyGroup.FillRule = FillRule.Nonzero;
                GeometryDrawing BodyDrawing = new GeometryDrawing(new SolidColorBrush(Color.FromRgb(70, 50, 40)), null, BodyGroup);

                GeometryGroup EyesGroup = new GeometryGroup();
                EyesGroup.Children.Add(new EllipseGeometry(new Point(0.43, 0.85), 0.03, 0.03));
                EyesGroup.Children.Add(new EllipseGeometry(new Point(0.57, 0.85), 0.03, 0.03));
                GeometryDrawing EyesDrawing = new GeometryDrawing(new SolidColorBrush(Color.FromRgb(120, 220, 220)), null, EyesGroup);

                Brush TransparentBrush = new SolidColorBrush(Colors.Pink);
                TransparentBrush.Opacity = 0;
                GeometryDrawing DrawingBox = new GeometryDrawing(TransparentBrush, null, new RectangleGeometry(new Rect(0, 0, 1, 1)));

                DrawingGroup DrawingGroup = new DrawingGroup();
                DrawingGroup.Children.Add(DrawingBox);
                DrawingGroup.Children.Add(BodyDrawing);
                DrawingGroup.Children.Add(EyesDrawing);

                RenderedBrush.Drawing = DrawingGroup;
                RenderedBrush.Viewbox = new Rect(0, 0, 1, 1);
                RenderedBrush.Viewport = new Rect(0, 0, 1, 1);
            }
            return RenderedBrush;
        }
    }
}
    